angular.module('start.user.money.getmoney.ctrl', [])

  .controller('getmoneyCtrl', function($scope, $rootScope, $$UserMoneyService, $ionicModal, $location, $ionicLoading) {
    console.log("getmoneyCtrl");

    $scope.getCashData = {
      money: 0,
      userName: "",
      bank: "",
      accoutNO: "",
      type: 1 // 1微信2支付宝3银行卡
    };

    $scope.getCashMsg = {
      wxaccout: "",
      zfbaccout: "",
      yhkname: "",
      yhkno: "",
      yhkkhh: "",
    };


    $scope.moneyData = {
      money: 0,
      profit: 0,
      bills: []
    };

    // 充值提交
    $scope.getCash_sub = function() {
      if ($scope.VformData()) {
        $$UserMoneyService.usergetCash($scope.getCashData)
          .then(function(res) {
            $ionicLoading.show({
              template: res.msg,
              noBackdrop: true,
              duration: 1500
            });
            $location.path("money");
          });
      }
    };

    // 查看余额信息
    $scope.getMoneymsg = function() {
      $$UserMoneyService.getusermoneymsg()
        .then(function(res) {
          $scope.moneyData.money = res.data.money;
        });
    };
    $scope.getMoneymsg();


    $scope.getmoneyway = function(type) {
      $scope.getCashData.type = type;
    };

    $scope.VformData = function() {
      if (!checkPrice($scope.getCashData.money) || $scope.getCashData.money <= 0) {
        $ionicLoading.show({
          template: "请正确填写价格",
          noBackdrop: true,
          duration: 1500
        });
        return false;
      }
      if ($scope.getCashData.type == 1) {
        $scope.getCashData.accoutNO = $scope.getCashMsg.wxaccout;
      } else if ($scope.getCashData.type == 2) {
        $scope.getCashData.accoutNO = $scope.getCashMsg.zfbaccout;
      } else if ($scope.getCashData.type == 3) {
        $scope.getCashData.userName = $scope.getCashMsg.yhkname;
        $scope.getCashData.accoutNO = $scope.getCashMsg.yhkno;
        $scope.getCashData.bank = $scope.getCashMsg.yhkkhh;
        if (!checkText($scope.getCashData.userName)) {
          $ionicLoading.show({
            template: "请填写姓名",
            noBackdrop: true,
            duration: 1500
          });
          return false;
        }
        if (!checkText($scope.getCashData.accoutNO)) {
          $ionicLoading.show({
            template: "请填写卡号",
            noBackdrop: true,
            duration: 1500
          });
          return false;
        }
      }
      if (!checkText($scope.getCashData.accoutNO)) {
        $ionicLoading.show({
          template: "请填写账号信息",
          noBackdrop: true,
          duration: 1500
        });
        return false;
      }
      return true;
    };

  });
